package com.nj.dms.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.nj.dms.bean.FileBean;
import com.nj.dms.dao.FileDao;
import com.nj.dms.dao.impl.FileDaoImpl;

/**
 * 查找一个文件
 */
@WebServlet("/FindFile")
public class FindFile extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		// 获取文件ID

		int id = new Integer(request.getParameter("id"));

		// 查找指定文件

		FileDao fileDao = new FileDaoImpl();

		FileBean file = fileDao.findFile(id);

		if (file != null) {

			// 文件存在，跳转到文件查看页

			request.setAttribute("file", file);

			request.getRequestDispatcher("document/look-file.jsp").forward(request, response);

		} else {
			// 文件找不到，跳转到文件列表

			response.sendRedirect("MyFileList");

		}

	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request, response);
	}

}
